package a;
import java.util.Random;
import java.util.Scanner;

public class RockPaperScissors {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        Random random = new Random();

        String[] options = {"石头", "剪刀", "布"};

        System.out.println("欢迎来到石头剪刀布游戏！");

        while (true) {
            System.out.println("请输入您的选择：（1.石头 2.剪刀 3.布）");
            int userSelected = scanner.nextInt() - 1;
            if (userSelected < 0 || userSelected > 2) {
                System.out.println("无效的选择，请重新输入！");
                continue;
            }

            int computerSelected = random.nextInt(3);
            System.out.println("电脑选择了：" + options[computerSelected]);

            if (userSelected == computerSelected) {
                System.out.println("平局！");
            } else if ((userSelected == 0 && computerSelected == 1)
                    || (userSelected == 1 && computerSelected == 2)
                    || (userSelected == 2 && computerSelected == 0)) {
                System.out.println("恭喜您，您赢了！");
            } else {
                System.out.println("很遗憾，您输了！");
            }

            System.out.println("是否继续游戏？（Y/N）");
            String again = scanner.next();
            if (!again.equalsIgnoreCase("Y")) {
                break;
            }
        }

        System.out.println("游戏结束！");
    }
}
